{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfbase.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<script type="text/javascript" src="{__PUBLIC_PATH}/common/js/jquery-ui.min.js?v={$version}"></script>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item sort-list">
                    {volist name='$menuList' id='vo'}
                    <div class="fl">
                      <input type="checkbox" lay-checkbox lay-skin="primary" lay-filter="checkedids" name="checkedids[]" value="{$vo.id}" title="{$vo.title}" data-ids="{$vo.id}" {if $vo.checked}checked{/if}>
                    </div>
                    {/volist}
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                </div>
            </div>
          </div>
        </div>
      </div>
    </div>
</div>
{include file="public/footer"/}
<script>
  layui.use(['layer', 'form'], function () {
    var $ = layui.$,
    layer = layui.layer,
    form = layui.form;
    //拖动排序相关 js
    $( ".sort-list" ).sortable({
        start: function( event, ui) {
        },stop: function( event, ui ) {
        }
    });
    $( ".sort-list" ).disableSelection();

    //监听每行复选框
    form.on('checkbox(checkedids)', function(data){
        if (data.elem.checked && 11 < $('input[name*=checkedids]:checked').length) {
            $(this).attr('checked', false);
            layer.msg("最多只勾选11个！", {icon: 2, time: 1000});
        }
        form.render('checkbox');
    });


    //监听提交
    form.on('submit(formSubmit)', function(data){
        layer.load(2);
        var ids = [];
        $("input[name^=checkedids]").each(function(index, item){
            ids.push($(item).data('ids'));
        })
        data.field.ids = ids;
        $.ajax({
            type : 'post',
            url : "{:url('/index/ajax_quickmenu')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        top.window.location.reload();
                    });
                }else{
                    parent.layer.msg(res.msg, {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll('loading');
                layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
            }
        });
        return false;
    })
  });
</script>